#pragma once
#include "ShareDataListener.h"

typedef enum _copy_data_type
{
    E_CDT_STRING    = 1,
    E_CDT_WSTRING   = 2,
    E_CDT_COUNT,
    E_CDT_UNKNOWN   = 0xFFFF,
}CDT, *LPCDT;

struct CopyData
{
    CDT             type;
    std::string     str;
    std::wstring    wstr;
};

class CShareData
{
public:
    CShareData();
    ~CShareData();

    bool    GetData(CopyData& data);

    DWORD   GetStamp();
    DWORD   WriteString(const std::wstring& wstr);
    DWORD   WriteString(const std::string& str);

    BOOL    RegisterListener(IShareDataListener* pListener);
    BOOL    UnregisterListener(IShareDataListener* pListener);

private:
    DWORD   _generate_stamp();
    VOID    _data_changed();


private:
    xBase::CxLock       m_oLock;
    CopyData            m_oData;
    DWORD               m_dwStamp;

    typedef std::vector<xBase::CScopedRefPtr<IShareDataListener>>  Listeners;
    Listeners           m_vecListners;

private:
    CShareData(const CShareData& other);
    CShareData& operator = (const CShareData& other);
};